package model;

/**
 *
 * @author Martin Mohr Pedersen
 */
public class OrderLineItem {

    private int qty;
    private Item item;
    private Double price;

    public OrderLineItem(Item item, int qty) {
        this.item = item;
        this.qty = qty;
    }
    
    public OrderLineItem(Item item, int qty, Double price) {
        this.item = item;
        this.qty = qty;
        this.price = price;
    }
    
    public Item getItem() {
        return item;
    }

    public int getQty() {
        return qty;
    }

    public void setQty(int qty) {
        this.qty = qty;
    }

    /**
     * Calculates the total price if price = null, returns price otherwise
     * @return
     */
    public double getPrice() {
        
        if(price == null) {
            price = item.getTotalPrice() * qty;
        }
        
        return price;
    }
    
}
